﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Prices
{
    class Product
    {
        string name;
        int price;
        private PriceIncreasedEventHandler priceIncreased;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public int Price
        {
            get { return price; }
            set {
                if (value > price)
                {
                    OnPriceIncrease(price, value);
                }
                if (value<0)
                {
                    throw new ArgumentException("Price can`t be negative.");
                }
                price = value;
            }
        }

        public Product(string name, int price)
        {
            this.Name = name;
            this.Price = price;
        }

        public event PriceIncreasedEventHandler PriceIncreased
        {
            add { priceIncreased += value; }
            remove { priceIncreased -= value; }
        }

        private void OnPriceIncrease(int oldPrice, int newPrice)
        {
            if (priceIncreased != null)
            {
                PriceIncreasedEventArgs args = new PriceIncreasedEventArgs(oldPrice, newPrice);
                priceIncreased(this, args);
            }
        }
    }
}
